package com.sunda.spmsuser.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmsuser.entity.SpmsUserWorkshop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户车间关联关系表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-01-25
 */
@Mapper
@Component
public interface SpmsUserWorkshopMapper extends BaseMapper<SpmsUserWorkshop> {

    @Select("SELECT suw.WERKS AS \"werks\",\n" +
            "  suw.WORKSHOP_CODE AS \"workshopCode\",\n" +
            "  w.WORKSHOP_NAME_ZH AS \"workshopNameZh\",\n" +
            "  w.WORKSHOP_NAME_EN AS \"workshopNameEn\",\n" +
            "  w.WORKSHOP_DESC AS \"workshopDesc\"\n" +
            "FROM SPMS_USER_WORKSHOP suw\n" +
            "  LEFT JOIN WORKSHOP w ON suw.WERKS = w.WERKS\n" +
            "                          AND suw.WORKSHOP_CODE = w.WORKSHOP_CODE\n" +
            "WHERE suw.WORK_CODE = #{userId}")
    List<Map<String, Object>> getUserWorkshopList(@Param("userId") String userId);
}
